package com.combining.c_decorator.main;

import com.combining.c_decorator.Goose;
import com.combining.c_decorator.face.Quackable;
import com.combining.c_decorator.impl.DuckCall;
import com.combining.c_decorator.impl.GooseAdapter;
import com.combining.c_decorator.impl.MallardDuck;
import com.combining.c_decorator.impl.QuackCounter;
import com.combining.c_decorator.impl.RedheadDuck;
import com.combining.c_decorator.impl.RubberDuck;

/**
 * 我们需要记录这些鸭子的叫声次数
 * 
 * @author dell
 * 
 */
// 然后，我们要计算呱呱叫声的次数。所以使用装饰者模式，添加了一个名称QuackCounter的装饰者。
// 它用来追踪quack()被调用的次数，并将调用委托给它所装饰的Quackable对象
public class DuckSimulator {
	public static void main(String[] args) {
		DuckSimulator simulator = new DuckSimulator();
		simulator.simulate();
	}

	void simulate() {
		Quackable mallardDuck = new QuackCounter(new MallardDuck());
		Quackable redheadDuck = new QuackCounter(new RedheadDuck());
		Quackable duckCall = new QuackCounter(new DuckCall());
		Quackable rubberDuck = new QuackCounter(new RubberDuck());
		Quackable gooseDuck = new GooseAdapter(new Goose());

		System.out.println("\n鸭子模拟器，和鹅适配器，和装饰者：");

		simulate(mallardDuck);
		simulate(redheadDuck);
		simulate(duckCall);
		simulate(rubberDuck);
		simulate(gooseDuck);

		System.out.println("鸭子共叫了" + QuackCounter.getQuacks() + "次");
	}

	void simulate(Quackable duck) {
		duck.quack();
	}
}
